<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/4
 * Time: 17:04
 */

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
class ShopGoods extends Model
{
    /**
     * 商品表
     * @var string
     */
    protected $table = 'shop_goods';
    protected $fillable = [
        'id' ,
        'cid',
        'goodsname',
        'rotation_chart',
        'type',
        'status',
        'number',
        'startTime',
        'timeprice',
        'limited_time',
        'originalprice',
        'costprice',
        'memberprice',
        'purchase_num',
        'rulingprice',
        'freight',
        'total',
        'sold',
        'totalcnf',
        'spec',
        'sort',
        'sorting',
        'straight',
        'createtime',
        'weight',
        'two_tid',
        'goods_thumb',
        'goods_type',
        'group_ids',
        'is_gift',
        'is_explosive',
        'is_brand',
        'is_source',
        'level',
        'pk_integral',
        'read_integral',
        'is_throw',
    ];

	/**
	 * @param int $goods_id
	 * @return bool|Model|null|static
	 */
	public function find_shop($goods_id = 0 ) {
		$goods = $this->where('id', $goods_id)->first();
		if ($goods) {
			return $goods;
		} else {
			return false;
		}
	}

	/**
	 * 获取全部商品
	 * @param array $where
	 * @param null $goods_id
	 * @return $this|bool
	 */
	public function get_goods($where = array(), $goods_id = null) {
		$table = $this->where(['type' => 1, 'status' => 1]);
		if ($where) {
			$table = $table->where($where);
		}
		if ($goods_id) {
			$table = $table->whereIn('id', $goods_id);
		}
		$goods = $table->get()->toArray();
		if ($goods) {
			return $goods;
		} else {
			return false;
		}
	}
}